<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
</head>
<body>
	<script>
		var Counter = (function() {
			var privateCounter = 0;
			function changeBy(val) {
				privateCounter += val;
			}
			return {
				increment: function() {
					changeBy(1);
				},
				decrement: function() {
					changeBy(-1);
				},
				value: function() {
					return privateCounter;
				}
			}   
		})();

		console.log(Counter.value()); /* logs 0 */
		Counter.increment();
		Counter.increment();
		console.log(Counter.value()); /* logs 2 */
		Counter.decrement();
		console.log(Counter.value()); /* logs 1 */
	</script>
</body>
</html>